﻿@model Model.AppUserList
@{
    ViewBag.Title = "商品批次打印";
    Layout = "~/Views/Shared/_JQBaseLayOut.cshtml";
}

@section JQscriptSection{
    <script src="../../Scripts/viewsScript/Common/MyDialog.js" type="text/javascript"></script>
    <script src="../../Scripts/jqueryeasyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.easy.ui.extend.js" type="text/javascript"></script>
    <script src="../../Scripts/Common.js" type="text/javascript"></script>
    <script type="text/javascript">
            function checkgoodscode() {
                var code = $.trim($("#txtBarCode").attr("value"));
                if (code != "") {
                    $('#item').form('submit', {
                        url: '@Url.Content("~/PrintGoodsBatchCode/checkGoodsExistByBarCode")',
                    success: function (data) {
                        eval('data=' + data);
                        if (data.success) {
                        } else {
                            $.messager.alert('错误', data.msg, 'error');
                            $("#txtBarCode").val("").focus();
                        }
                    }
                });
            }
        };
        function CreateCode() {
            var BarCode = $.trim($("#txtBarCode").attr("value"));
            var ProductionDate = $("#ProductionDate").datebox('getValue');
            var ExpiryDays = $.trim($("#txtExpiryDays").attr("value"));
            if (BarCode == "") {
                $.messager.alert('提示', '商品条码不能为空', 'warning');
                $("#txtBarCode").focus();
                return false;
            }
            if (ProductionDate == "") {
                $.messager.alert('提示', '生产日期不能为空', 'warning');
                $("#txtProductionDate").focus();
                return false;
            }
            $('#item').form('submit', {
                url: "/PrintGoodsBatchCode/CreateImage"
                    + '?BarCode=' + BarCode + '&ProductionDate=' + ProductionDate + '&ExpiryDays=' + ExpiryDays,
                success: function (data) {
                    eval('data=' + data);
                    if (data.success) {
                        //$('#barcode').attr("src") = data.msg;
                        var imgNode = $("#barcode");
                        imgNode.attr("src", data.msg);
                        //preview();
                    } else {
                        $.messager.alert('错误', data.msg, 'error');
                        //alert("保存失败！请检查");
                    }
                }
            });
        }
        function preview() {
            var bdhtml = window.document.body.innerHTML;

            var sprnstr = "<!--startprint-->";
            var eprnstr = "<!--endprint-->";
            var prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
            var prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
            window.document.body.innerHTML = prnhtml;
            window.print();
            window.document.body.innerHTML = bdhtml;
        }


    </script>
}
<body style="background-color: ButtonFace; font-size: 17px">

    <form id="item" method="post">
        <div id="p1" class="easyui-panel" title="打印条件" style="height: 35px; padding: 5px; background: #fafafa;">
            <table>
                <tr>
                    <td>商品条码:
                    </td>
                    <td>
                        <input id="txtBarCode" name="txtBarCode" maxlength="10" style="width: 154px" onblur="checkgoodscode()" />
                    </td>
                    <td>生产日期:
                    </td>
                    <td>
                        <input class="easyui-datebox" id="ProductionDate" name="ProductionDate" style="width: 154px;" />
                    </td>
                    <td>保质期:
                    </td>
                    <td>
                        <input id="txtExpiryDays" name="txtExpiryDays" style="width: 154px" />
                    </td>
                    <td></td>
                    <td>
                        <a id="btnBarCode" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-print'" onclick="CreateCode()">生成条形码</a>
                    </td>
                    <td>
                        <a id="btnPrint" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-print'" onclick="preview()">打印</a>
                    </td>
                </tr>
            </table>
        </div>
        <!--startprint-->
        <div>
            <table id="tab_list">
                <tr>
                    <td>
                        <img id="barcode" src="" width="300" height="100" align="absmiddle" />
                    </td>
                </tr>
            </table>
        </div>
        <!--endprint-->
    </form>
</body>
